


function submit() {
    if(confirm("你确定要删除？")){
    $.ajax({
        url:url,
        type:"post",
        dataType:"text",
        data:$("#forms").serialize(),
        success:function (data) {
//             alert(data)                                     //测试data
            if(data=="1"){                                 //判断是否成功
                alert("删除成功");
                location.href=locationurl;
            }else{
                alert("删除失败")
            }
        },
        error:function (e) {
            alert(e.response)
        }
    });
    }
}
function onchaange(id) {
//        alert(id.value);
    $.ajax({
        url: chengeurl,
        type: "post",
        dataType: "json",
        data: {
            id: id.value
        },
        success: function (data) {
//            alert(data[0].record_name)
            $("#fine").empty();
            for (var i = 0; i < Object.keys(data).length; i++) {  //获取data长度   循环遍历出来
                $("#fine").append('<option value=' + data[i].id + '>' + data[i].record_name + '</option>')
            }
        },
        error: function (e) {
            alert(e.response)
        }
    })
}
$.validator.setDefaults({
    submitHandler: function() {

        submit();
    }
});
$(function () {
    $("#forms").validate({
        rules: {
            record_name: {
                required: true,
                maxlength: 24
            },
            category: {
                required: true
            },
            introduce: {
                required: true,
                maxlength: 32
            },
            difficulty: {
                required: true
            },
            charge: {
                minNumber:true,
                required: true
            }
        },
        messages: {
            record_name: {
                required: "请输入用户名"
            }

        }
    });
    jQuery.validator.addMethod("minNumber",function(value, element){
        var returnVal = true;
        inputZ=value;
        if(isNaN(value)){
            returnVal=false
            return false;
        }
        var ArrMen= inputZ.split(".");    //截取字符串
        if(ArrMen.length==2){
            if(ArrMen[1].length>2){    //判断小数点后面的字符串长度
                returnVal = false;
                return false;
            }
        }

        return returnVal;
    },"纯数字 最多保留两位小数点");


})/**
 * Created by Administrator on 2017/7/18.
 */
